<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组的reduce方法</title>
    <link href="./img/logo.png" rel="shortcut icon">
</head>
<body>

   <script>
       const arr = [
           { id:1,name:'甘雨',status:true,dowry:1400,count:1 },
           { id:2,name:'心海',status:true,dowry:1400,count:1 },
           { id:3,name:'凌华',status:true,dowry:12960,count:1 }
       ]

       // 将数组里勾选的项,总价累计起来
       // let amt = 0  // 定义一个总价
       // arr.filter(item => item.status).forEach(item => {
       //     amt += item.dowry * item.count
       // })
       // console.log(amt)

       // 使用 reduce
       /* 语法：
        arr.filter(item => item.status).reduce((累加的结果,当前循环项)=>{ },初始值) */
       const result = arr.filter(item => item.status).reduce((amt,item)=>{
           return amt += item.count * item.dowry
       },0)
       console.log(result)




   </script>
</body>
</html>